﻿
class SingleChartBase extends ChartBase
{ 
	 //图例数据
	var mLegendLeft : Number = 20;				//图例的左边界	
	var mLegendTop : Number = 10;				//图例数据顶部偏移
	var mLegendWidth : Number = 100;			//图例宽度	 
	var mLegendYGap : Number = 18;				//图例间Y轴上的间距
	var mLegendXGap : Number = 5;				//图例内容相对于图例边界的偏移	
	var mLegendOption : Array = new Array();	//图例数据选项
	
	//图表宽度
	var mChartLeft : Number = 10 ;
	var mChartWidth : Number = 0;
	var mChartTop : Number = 0;
	var mChartHeight : Number = 0;
	var mChartRight : Number = 0;
		
	//图表X轴上的坐标分布
	var mChartCoordinate : Array = new Array();		//成员：坐标值，X轴偏移，对应时间点（精确到天）
	//X轴上的最小间隔
	var mChartXGap : Number = 0;
	//X轴上的有效坐标数
	var mChartXCount : Number = 0;
	//X轴上最下间隔对应的时间单元（以天为单位）
	var mChartXUnit : Number = 0 ;
	//X轴上有效起始点
	var mChartXValidPos : Number = 0;
	//每小段中细分的个数
	var mSegmentCount = 4;
	
	//其它
	var mDefaultColor:Number = 0x000000;		//默认的字体颜色
	 
	//最新更新时间
	var mUpdateDate : Date;
	//起始时间
	var mStartDate : Date;
	//确诊时间
	var mDosageDate : Date;
	
	 //每个显示点对应的MovieClip，以及相应的ToolTip
	 var mChildmcArr : Array;		
	    
	function SingleChartBase()
	{
		//设置一些默认数据
		mChartWidth = 600;
		mChartXValidPos = 0;
		mChartTop = mLegendTop + 30 ;
	}
     
	function ParseBase(lv : Object)
	{
        mUpdateDate = Utils.StrToDate(lv["UpdateDate"]);
		mDosageDate = Utils.StrToDate(lv["DosageDate"]);
		mStartDate = mDosageDate;
		
		mChartRight = mChartLeft + mChartWidth + 1;		
    }
	
    //根据时间差来确定X轴坐标值 
	private function SetXCoordinate(startDate:Date, endDate:Date)
	{
		var diffYear = endDate.getYear() - startDate.getYear();
		var diffMonth = diffYear*12 + endDate.getMonth() - startDate.getMonth(); 
		var diffDay = Utils.GetDayNumber(endDate, startDate);		
		
		// 按照天数的差值计算坐标
		mChartXCount = mSegmentCount*8 ;
		mChartXUnit = diffDay*1.0/mChartXCount ;
		mChartXGap = mChartWidth*1.0/mChartXCount;
		
		//设置坐标值，格式如：12/2007
		for(var i=1; i<=mChartXCount/mSegmentCount; i++)
		{
			var tmpDate : Date = Utils.GetDate(startDate, mChartXUnit*i*mSegmentCount);
			mChartCoordinate.push([Utils.DateToStrNoDay(tmpDate), i*mSegmentCount*mChartXGap, tmpDate]);
		}		
	}
	
	//根据时间获得相对于X轴起始点的X偏移距离
	public function GetXMigration(dt:Date)
	{
		var retVal = 0;
		var migrateDay = Utils.GetDayNumber(dt, mStartDate);		
		if(migrateDay < 0)
		{
			return -1;
		}
		
		retVal = mChartXValidPos + ((migrateDay*1.0)/mChartXUnit)*mChartXGap ;
		if(retVal > mChartWidth - mChartXValidPos)
		{
			retVal = -1;
		}
		
		return retVal ;
	}
	
	//以特定风格显示文本
	public function DrawText(textName:String, x:Number, y:Number, textColor:Number, size:Number, align:String)
	{
		var mc : MovieClip = mClip;
		
		var textformat = new TextFormat();
		textformat.color = Color(textColor);
		textformat.align = align;
		textformat.size  = 10;
		
		var label:TextField = mc.createTextField(textName, mc.getNextHighestDepth(), x, y, 0, 0);		
		label.setTextFormat(textformat);
		label.html = true;
		label.autoSize = align;
		label.htmlText = textName;		
		label.textColor = textColor;
	}		
}